package com.goktech.olala.client.controller.index;

import com.goktech.olala.core.req.ReqGoodkey;
import com.goktech.olala.core.service.IGoodIndexService;
import com.goktech.olala.server.pojo.goods.Good;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @auther : 朱正标
 * @create time : 2020/12/4 20:25
 * @description :
 */
@RestController
@RequestMapping("/goodsIndexApi")
public class IndexGoodController {

    @Autowired
    IGoodIndexService goodIndexService;

    @RequestMapping("/queryGoodsByParam.do")
    public ModelAndView queryGoodsByParam(HttpServletRequest request){
        ModelAndView mv =new ModelAndView();
        String keywords = request.getParameter("keywords");

        ReqGoodkey goodkey = new ReqGoodkey();

        goodkey.setKeywords(keywords);

        List<Good> goods = goodIndexService.selectByKey(goodkey);

        mv.addObject("goodsList",goods);

        mv.setViewName("home/search");
        return mv;
    }
}
